<!DOCTYPE html>
<html>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,minimum-scale=1.0,maximum-scale=1.0" />
  <meta name="author" content="火星科技 http://mars3d.cn ">
  <meta name="apple-touch-fullscreen" content="yes">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no">
  <meta name="x5-fullscreen" content="true">
  <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1" />


  <!-- 标题及搜索关键字 -->
  <meta name="keywords" content="火星科技,cesium,3D,GIS,marsgis,三维,地球,地图,开发,框架,系统,示例,资料,模型,离线,外包,合肥,安徽,中国" />
  <meta name="description"
        content="火星科技 合肥火星 合肥火星科技 合肥火星科技有限公司 leaflet leaflet框架 leaflet开发 cesium cesium开发 cesium框架 三维 地球 模型  gis marsgis 地图离线 地图开发 地图框架 地图外包 框架 开发 外包  地图离线 二维地图 三维地图 全景漫游 地理信息系统 云GIS 三维GIS GIS平台 WebGIS" />

  <link rel="shortcut icon" type="image/x-icon" href="http://mars3d.cn/favicon.ico">
  <title>视频投放 | Mars3D | 三维地图 | 火星科技 | 合肥火星科技有限公司</title>



  <!--第三方lib-->
  <script type="text/javascript" src="../lib/include-lib.js" libpath="../lib/" include="jquery,jquery.range,font-awesome,bootstrap,bootstrap-checkbox,layer,haoutil,turf,mars3d"></script>

  <link href="css/style.css" rel="stylesheet" />
</head>

<body class="dark">
  <!--加载前进行操作提示，优化用户体验-->
  <div id="mask" class="signmask" onclick="removeMask()"></div>

  <div id="mars3dContainer" class="mars3d-container"></div>


  <!-- 面板 -->
  <div class="infoview">
    <input type="button" class="btn btn-primary" value="贴地矩形" onclick="drawRectangle()" />
    <input type="button" class="btn btn-primary" value="贴地面" onclick="drawPolygon(true)" />
    <input type="button" class="btn btn-primary" value="立体面" onclick="drawPolygon(false)" />
    <input type="button" class="btn btn-primary" value="清除" onclick="removeAll()" />

    <table class="mars-table">
      <tbody>
        <tr>
          <td>方向:</td>
          <td>
            <input id="txtAngle" type="range" min="0" max="360" step="1" value="0">
          </td>
        </tr>
        <tr>
          <td>状态:</td>
          <td>

            <button id="video-play" type="button" class="btn btn-primary">
              <span class="fa fa-pause" aria-hidden="true"></span> 暂停
            </button>

          </td>
        </tr>
      </tbody>
    </table>
  </div>

  <video id="trailer" style="display: none;" muted="muted" autoplay="autoplay" loop="loop" crossorigin="" controls="">
    <source src="http://data.marsgis.cn/video/lukou.mp4" type="video/mp4">
  </video>


  <script src="./js/common.js"></script>
  <script type="text/javascript">
    'use script' //开发环境建议开启严格模式

    var map
    var graphicLayer
    var videoElement

    function initMap(options) {
      //合并属性参数，可覆盖config.json中的对应配置
      var mapOptions = mars3d.Util.merge(options, {
        scene: {
          //此处参数会覆盖config.json中的对应配置
          center: {
            y: 28.440942,
            x: 119.482189,
            z: 191.32,
            heading: 227.4,
            pitch: -27.6,
            roll: 359.9,
          },
        },
      })

      //创建三维地球场景
      map = new mars3d.Map('mars3dContainer', mapOptions)

      //添加参考三维模型
      var tiles3dLayer = new mars3d.layer.TilesetLayer({
        name: '县城社区',
        url: 'http://data.marsgis.cn/3dtiles/qx-shequ/tileset.json',
        maximumScreenSpaceError: 2,
        maximumMemoryUsage: 1024,
        position: { alt: 3 },
      })
      map.addLayer(tiles3dLayer)

      videoElement = document.getElementById('trailer')

      //可以使视频元素与Cesium的模拟时钟同步
      let synchronizer = new Cesium.VideoSynchronizer({
        clock: map.clock,
        element: videoElement,
      })
      map.clock.shouldAnimate = true

      $('#video-play').click(function () {
        if (map.clock.shouldAnimate) {
          map.clock.shouldAnimate = false
          $(this).html('<span class="fa fa-play" aria-hidden="true"></span> 播放')
        } else {
          map.clock.shouldAnimate = true
          $(this).html('<span class="fa fa-pause" aria-hidden="true"></span> 暂停')
        }
      })

      $('#txtAngle').range({
        onChange: function (value, bfb) {
          rotation = Cesium.Math.toRadians(value)
        },
      })

      //允许编辑
      map.graphicLayer.hasEdit = true

      //创建矢量数据图层
      graphicLayer = new mars3d.layer.GraphicLayer()
      map.addLayer(graphicLayer)

      //2.在layer上绑定监听事件
      graphicLayer.on(mars3d.EventType.click, function (event) {
        console.log('监听layer，单击了矢量对象', event)
      })
      graphicLayer.on(mars3d.EventType.mouseOver, function (event) {
        console.log('监听layer，鼠标移入了矢量对象', event)
      })
      graphicLayer.on(mars3d.EventType.mouseOut, function (event) {
        console.log('监听layer，鼠标移出了矢量对象', event)
      })

      //可在图层上绑定popup,对所有加到这个图层的矢量数据都生效
      graphicLayer.bindPopup('我是layer上绑定的Popup', {
        anchor: [0, -10],
      })

      //可在图层上绑定tooltip,对所有加到这个图层的矢量数据都生效
      // graphicLayer.bindTooltip('我是layer上绑定的Tooltip')

      //可在图层绑定右键菜单,对所有加到这个图层的矢量数据都生效
      graphicLayer.bindContextMenu([
        {
          text: '删除对象',
          iconCls: 'fa fa-trash-o',
          callback: function (e) {
            var graphic = e.graphic
            if (graphic) {
              graphicLayer.removeGraphic(graphic)
            }
          },
        },
      ])

      //加一些演示数据
      addGraphic_01(graphicLayer)
      addGraphic_02(graphicLayer)
    }

    //竖立视频
    function addGraphic_01(graphicLayer) {
      var graphic = new mars3d.graphic.PolygonEntity({
        positions: [
          [119.481299, 28.439988, 131],
          [119.481162, 28.440102, 131],
          [119.481163, 28.440101, 122],
          [119.481296, 28.439986, 122],
        ],
        style: {
          material: videoElement,
          stRotationDegree: 0, //视频旋转角度
          perPositionHeight: true,
          outline: false,
        },
      })
      graphicLayer.addGraphic(graphic)
    }

    //地面视频
    function addGraphic_02(graphicLayer) {
      var graphic = new mars3d.graphic.PolygonEntity({
        positions: [
          [119.481749, 28.440171],
          [119.481385, 28.440457],
          [119.481911, 28.44094],
          [119.482254, 28.440653],
        ],
        style: {
          material: videoElement,
          stRotationDegree: 130, //视频旋转角度
          perPositionHeight: false,
          outline: false,
        },
      })
      graphicLayer.addGraphic(graphic)
    }

    var rotation = 0
    function getRotationValue() {
      return rotation
    }

    function drawRectangle() {
      map.graphicLayer.startDraw({
        type: 'rectangle',
        style: {
          color: '#ffff00',
          opacity: 0.2,
          clampToGround: true,
        },
        success: function (graphic) {
          graphic.entityGraphic.material = videoElement

          graphic.entityGraphic.rotation = new Cesium.CallbackProperty(getRotationValue, false)
          graphic.entityGraphic.stRotation = new Cesium.CallbackProperty(getRotationValue, false)
        },
      })
    }

    //绘制这个polygon的时候，点的绘制顺序和面的角度不同，会使画面翻转
    function drawPolygon(clampToGround) {
      map.graphicLayer.startDraw({
        type: 'polygon',
        style: {
          color: '#ffff00',
          opacity: 0.2,
          clampToGround: clampToGround,
        },
        success: function (graphic) {
          graphic.entityGraphic.material = videoElement
          graphic.entityGraphic.stRotation = new Cesium.CallbackProperty(getRotationValue, false)
        },
      })
    }

    function removeAll() {
      map.graphicLayer.clear()
      graphicLayer.clear()
    }
  </script>
</body>

</html>
